import jwt
import datetime
from django.conf import settings
# 生成token函数
SALT = settings.SECRET_KEY #密令
def createToken(payload,timeout):

    #1.jwt 用户验证后生成的token
    headers = {
        "alg": "HS256",
        "typ": "JWT"
    }
    # payload = {'user_id': '', 'username': '', 'exp': ''}
    payload['exp'] = datetime.datetime.utcnow() + datetime.timedelta(minutes=timeout)


    token = jwt.encode(payload=payload,key=SALT,algorithm="HS256",headers=headers).decode('utf-8')
    print(token)

    return token